package com.common.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @Author: luo
 * @Description:
 * @Data: 10:07 2022/5/31
 */
public class PasswordUtils {

    /**密码加密*/
    private static final BCryptPasswordEncoder passwordEncoder =new BCryptPasswordEncoder();

    /**
     * @Author: luo
     * @Description: 密码加密
     * @param password 密码
     * @Data: 17:06 2021/6/30
     */
    public static String encode(String password){
        return  passwordEncoder.encode(password);
    }

    /**
     * @Author: luo
     * @Description: 密码校验
     * @param oldPassword 旧密码（经过MD5加密）
     * @param encodePassword 经过加密的密码
     * @Data: 8:57 2021/7/1
     */
    public static boolean matches(String oldPassword,String encodePassword){
        return passwordEncoder.matches(oldPassword, encodePassword);
    }

    public static void main(String[] args) {
        String password = encode(Md5Utils.toUpperCase32("123456"));
        System.out.println(password);
    }
}
